﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace CIT.WMS.RM.Bll
{
    class Bll_CenterCode
    {
        public static DataTable GetInfo(string inBillNo)
        {
            string sqlcmd = string.Format(@"select * from wms_T_Request where BillNo = '{0}' and status = 0",
                                            inBillNo);
            var result = Utils.NMS.GetDataTable(sqlcmd);
            return result;
        }

        public static DataTable GetLocation(string inBillNo)
        {
            string sqlcmd = string.Format(@"select Top 1 r.BillNo,r.PartNumber,i.Version,i.Location_SN from wms_T_Request r 
                                            inner join wms_T_Inventory i on r.PartNumber = i.PartNumber and r.Storage_SN = i.Storage_SN
                                            where BillNo = '{0}' ORDER BY DateCode",
                                            inBillNo);
            var result = Utils.NMS.GetDataTable(sqlcmd);
            return result;
        }

        public static DataTable CheckLocation(string inBillNo)
        {
            string sqlcmd = string.Format(@"select Top 1 r.BillNo,r.PartNumber,i.Version,r.Location_SN from wms_T_Request r 
                                            inner join wms_T_Inventory i on r.PartNumber = i.PartNumber and r.Storage_SN = i.Storage_SN
                                            where BillNo = '{0}' ORDER BY DateCode",
                                            inBillNo);
            var result = Utils.NMS.GetDataTable(sqlcmd);
            return result;
        }

        public static int Query(string billno, string userName, string locationSN, decimal qty)
        {
            string sqlcmd = string.Format(@"begin 
                                            DECLARE @ret INT;
                                            exec @ret=PDA_CenterCode_query @billNo=N'{0}', @userName=N'{1}',@locationSN=N'{2}',@qty={3};
                                            SELECT @ret 
                                            end",
                                            billno, userName, locationSN, qty);
            var result = Utils.NMS.GetDataTable(sqlcmd);
            return Convert.ToInt16(result.Rows[0][0]);
        }

        public static int QCenterCode(string billno, string userName, string locationSN, decimal qty)
        {
            string sqlcmd = string.Format(@"begin 
                                            DECLARE @ret INT;
                                            exec @ret=PDA_QCenterCode @billNo=N'{0}', @userName=N'{1}',@locationSN=N'{2}',@qty={3};
                                            SELECT @ret 
                                            end",
                                            billno, userName, locationSN, qty);
            var result = Utils.NMS.GetDataTable(sqlcmd);
            return Convert.ToInt16(result.Rows[0][0]);
        }

    }
}
